package com.cn.wanxi.servlet;


import com.alibaba.fastjson.JSONObject;
import com.cn.wanxi.model.CompanyModel;
import com.cn.wanxi.model.NavModel;
import com.cn.wanxi.service.ICompanyService;
import com.cn.wanxi.service.INavService;
import com.cn.wanxi.service.impl.CompanyServiceImpl;
import com.cn.wanxi.service.impl.NavServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/home")
public class HomeServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        ICompanyService iCompanyService = new CompanyServiceImpl();
//        CompanyService companyService = new CompanyService();//逻辑层
        CompanyModel companyModel = iCompanyService.getCompanyModel();
//        req.setAttribute("companyModel", companyModel);
//        加载导航信息
        INavService iNavService = new NavServiceImpl();
        List<NavModel> navModelList = iNavService.getNavModelList();
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("companyModel",companyModel);
        jsonObject.put("navModelList",navModelList);
        resp.getWriter().println(jsonObject);
//        String[] titles = {};
//        String[] hrefs = {};
//        NavModel[] navModels = {new NavModel(), new NavModel()};
//        req.setAttribute("titles", titles);
//   如果要拿到数组的值，则需要遍历

//        req.setAttribute("hrefs", hrefs);
//        导航数据的封装应该在service服务逻辑层里面
//        NavService navService = new NavService();
//        Object  所有引用類型的超类
//        Object
//        req.setAttribute("navModels", navService.getNavModels());

//新闻信息
//        NewsService newsService = new NewsService();
//        req.setAttribute("newsModels", newsService.getHomeService());
//        req.setAttribute("navModels", navModelList);
//        req.getRequestDispatcher("jsp/home.jsp").forward(req, resp);//页面转发，需要转发地址
    }
}
